package com.iknow.data;

import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import com.iknow.IKnow;
import com.iknow.IKnowApiV4;
import com.iknow.IKnowResponse;
import com.iknow.QingboResponse;
import com.iknow.db.IKnowDataBase;
import com.iknow.http.HttpException;
import com.iknow.http.Response;
import com.iknow.util.Loger;
import com.iknow.util.StringUtil;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class QingBo
  implements Parcelable
{
  public static final Parcelable.Creator<QingBo> CREATOR = new Parcelable.Creator()
  {
    public QingBo createFromParcel()
    {
      return new QingBo(paramParcel, null);
    }

    public QingBo[] newArray()
    {
      return null;
    }
  };
  private final String TAG = "QingBo";
  private String mAuthorAvatar;
  private String mAuthorJid;
  private String mCommentCount;
  private Date mCreateDate;
  private String mDisplayName;
  private String mFavCount;
  private String mHot;
  private String mID;
  private String mSubject;
  private String mTags;
  private String mThumbnailUrl;
  private String mTitle;
  private QingboType mType;

  private QingBo(Parcel paramParcel)
  {
    this.mID = paramParcel.readString();
    this.mCreateDate = new Date(paramParcel.readLong());
    this.mSubject = paramParcel.readString();
    this.mTitle = paramParcel.readString();
    this.mHot = paramParcel.readString();
    this.mFavCount = paramParcel.readString();
    this.mCommentCount = paramParcel.readString();
    this.mType = QingboType.formString(paramParcel.readString());
    this.mThumbnailUrl = paramParcel.readString();
    this.mAuthorJid = paramParcel.readString();
    this.mDisplayName = paramParcel.readString();
    this.mTags = paramParcel.readString();
    this.mAuthorAvatar = paramParcel.readString();
  }

  public QingBo(QingboResponse paramQingboResponse)
  {
    this.mID = paramQingboResponse.getID();
    this.mTitle = paramQingboResponse.getTitle();
    this.mSubject = paramQingboResponse.getSubject();
    this.mHot = paramQingboResponse.getHot();
    this.mFavCount = paramQingboResponse.getFavoriteCount();
    this.mCommentCount = paramQingboResponse.getCommentCount();
    this.mType = paramQingboResponse.getType();
    this.mThumbnailUrl = IKnowApiV4.getResizeThumbnailImageUrl(paramQingboResponse.getThumbnailUrl());
    this.mAuthorJid = paramQingboResponse.getAuthorID();
    this.mDisplayName = paramQingboResponse.getAuthorName();
    if (StringUtil.isEmpty(this.mDisplayName))
      this.mDisplayName = "匿名";
    this.mTags = paramQingboResponse.getTags();
    this.mCreateDate = paramQingboResponse.getCreateTime();
    this.mAuthorAvatar = IKnow.mIKnowDataBase.getFriendAvatarUrl(this.mAuthorJid + "@" + "imiknow.com");
    if (this.mAuthorAvatar == null)
      this.mAuthorAvatar = paramQingboResponse.getAuthorHeadImage();
  }

  public QingBo(String paramString1, String paramString2, String paramString3, Date paramDate, String paramString4, String paramString5, String paramString6)
  {
    this.mID = paramString1;
    this.mTitle = paramString2;
    this.mSubject = paramString3;
    this.mCreateDate = paramDate;
    this.mThumbnailUrl = paramString4;
    this.mDisplayName = paramString5;
    this.mAuthorJid = paramString6;
  }

  public QingBo(JSONObject paramJSONObject)
    throws HttpException
  {
    try
    {
      init(paramJSONObject);
      return;
    }
    catch (JSONException localJSONException)
    {
      Loger.e("QingBo", "Create QingboResponse error:" + localJSONException.getMessage());
      localJSONException.printStackTrace();
    }
  }

  public static List<QingBo> QingboResponses(Response paramResponse)
    throws HttpException
  {
    JSONArray localJSONArray;
    try
    {
      localJSONArray = paramResponse.asJSONArray();
      ArrayList localArrayList = new ArrayList(localJSONArray.length());
      int i = 0;
      if (i >= localJSONArray.length())
        return localArrayList;
      localArrayList.add(new QingBo(localJSONArray.getJSONObject(i)));
      ++i;
    }
    catch (JSONException localJSONException)
    {
      throw new HttpException(localJSONException);
    }
  }

  private String getTags(JSONArray paramJSONArray)
  {
    StringBuilder localStringBuilder = new StringBuilder();
    int i = 0;
    if (i >= paramJSONArray.length())
    {
      int j = localStringBuilder.length();
      if (j > 0)
        localStringBuilder.deleteCharAt(j - 1);
      return localStringBuilder.toString();
    }
    try
    {
      localStringBuilder.append(paramJSONArray.getString(i)).append(",");
      ++i;
    }
    catch (JSONException localJSONException)
    {
      while (true)
        localJSONException.printStackTrace();
    }
  }

  private void init(JSONObject paramJSONObject)
    throws JSONException, HttpException
  {
    JSONObject localJSONObject;
    if (paramJSONObject.has("content"))
    {
      localJSONObject = (JSONObject)paramJSONObject.get("content");
      this.mID = localJSONObject.getString("id");
      this.mTitle = localJSONObject.getString("name");
      this.mSubject = localJSONObject.getString("des");
      if (!(StringUtil.isEmpty(this.mSubject)))
        this.mSubject = this.mSubject.replace("\r\n", "\n");
      this.mHot = localJSONObject.getString("open_count");
      this.mFavCount = localJSONObject.getString("favorite_count");
      this.mCommentCount = localJSONObject.getString("comment_count");
      this.mType = QingboType.formString(localJSONObject.getString("type"));
      this.mThumbnailUrl = IKnowApiV4.getResizeThumbnailImageUrl(localJSONObject.getString("image_url"));
      this.mCreateDate = IKnowResponse.parseDate(localJSONObject.getString("create_time"), "yyyy-MM-dd HH:mm:ss");
      this.mAuthorAvatar = IKnow.mIKnowDataBase.getFriendAvatarUrl(this.mAuthorJid + "@" + "imiknow.com");
      if (this.mAuthorAvatar == null)
        this.mAuthorAvatar = IKnowApiV4.getResizeAvatarImageUrl(localJSONObject.getString("user_photo"));
      this.mAuthorJid = localJSONObject.getString("user_id");
      this.mDisplayName = localJSONObject.getString("user_name");
      if (!(localJSONObject.has("tags")))
        break label268;
      this.mTags = getTags(localJSONObject.getJSONArray("tags"));
    }
    while (true)
    {
      while (true)
      {
        return;
        localJSONObject = paramJSONObject;
      }
      label268: this.mTags = "测试";
    }
  }

  public int describeContents()
  {
    return 0;
  }

  public String getAuthorAvatar()
  {
    return this.mAuthorAvatar;
  }

  public String getAuthorID()
  {
    return this.mAuthorJid;
  }

  public String getAuthorName()
  {
    return this.mDisplayName;
  }

  public String getCommentCount()
  {
    return this.mCommentCount;
  }

  public Date getCreateTime()
  {
    return this.mCreateDate;
  }

  public String getFavoriteCount()
  {
    return this.mFavCount;
  }

  public String getHot()
  {
    return this.mHot;
  }

  public String getID()
  {
    return this.mID;
  }

  public String getSubject()
  {
    return this.mSubject;
  }

  public String getTags()
  {
    return this.mTags;
  }

  public String getThumbnailUrl()
  {
    return this.mThumbnailUrl;
  }

  public String getTitle()
  {
    return this.mTitle;
  }

  public QingboType getType()
  {
    return this.mType;
  }

  public void setAuthorAvatar(String paramString)
  {
    this.mAuthorAvatar = paramString;
  }

  public void setCommentCount(String paramString)
  {
    this.mCommentCount = paramString;
  }

  public void setHot(String paramString)
  {
    this.mHot = paramString;
  }

  public void setQingboType(QingboType paramQingboType)
  {
    this.mType = paramQingboType;
  }

  public void setTag(String paramString)
  {
    this.mTags = paramString;
  }

  public void setThumbnailUrl(String paramString)
  {
    this.mThumbnailUrl = paramString;
  }

  public void setfavoriteCount(String paramString)
  {
    this.mFavCount = paramString;
  }

  public void writeToParcel(Parcel paramParcel, int paramInt)
  {
    paramParcel.writeString(this.mID);
    paramParcel.writeLong(this.mCreateDate.getTime());
    paramParcel.writeString(this.mSubject);
    paramParcel.writeString(this.mTitle);
    paramParcel.writeString(this.mHot);
    paramParcel.writeString(this.mFavCount);
    paramParcel.writeString(this.mCommentCount);
    paramParcel.writeString(this.mType.toString());
    paramParcel.writeString(this.mThumbnailUrl);
    paramParcel.writeString(this.mAuthorJid);
    paramParcel.writeString(this.mDisplayName);
    paramParcel.writeString(this.mTags);
    paramParcel.writeString(this.mAuthorAvatar);
  }
}